package com.md.api.controller;

import com.md.api.annotation.NoRepeatSubmit;
import com.md.api.common.utils.StringUtils;
import com.md.api.entity.HttpResult;
import com.md.api.entity.ReceivingAddrInfo;
import com.md.api.entity.dto.ComposeCommitDto;
import com.md.api.service.ReceivingAddrSevice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@RequestMapping("/addr")
@RestController
public class ReceivingAddrController {


	@Resource
	ReceivingAddrSevice addrSevice;




	//新增收货地址
	@NoRepeatSubmit
	@RequestMapping("/addReceivingAddr")
	public HttpResult addReceivingAddr(HttpServletRequest request,@RequestBody ReceivingAddrInfo addrInfo) {
//		if (null==addrInfo.getNumCount()|| StringUtils.isEmpty(shoppingCart.getSpuId())||StringUtils.isEmpty(shoppingCart.getSkuId())){
//			return HttpResult.PARAM_ERROR;
//		}
		return addrSevice.addReceivingAddr(request,addrInfo);
	}

	//新增收货地址
	@NoRepeatSubmit
	@RequestMapping("/updateReceivingAddr")
	public HttpResult updateReceivingAddr(HttpServletRequest request,@RequestBody ReceivingAddrInfo addrInfo) {
//		if (null==addrInfo.getNumCount()|| StringUtils.isEmpty(shoppingCart.getSpuId())||StringUtils.isEmpty(shoppingCart.getSkuId())){
//			return HttpResult.PARAM_ERROR;
//		}
		return addrSevice.updateReceivingAddr(request,addrInfo);
	}

	//我的地址
	@RequestMapping("/myAddr")
	public HttpResult myAddr(HttpServletRequest request) {
		return addrSevice.myAddr(request);
	}


	//我的地址
	@RequestMapping("/myDefaltAddr")
	public HttpResult myDefaltAddr(HttpServletRequest request) {
		return addrSevice.myDefaltAddr(request);
	}

	//设为默认地址
	@NoRepeatSubmit
	@RequestMapping("/setDefault")
	public HttpResult setDefault(HttpServletRequest request,@RequestBody ComposeCommitDto qto) {
		if (StringUtils.isEmpty(qto.getReceivingAddrId())){
			return HttpResult.PARAM_ERROR;
		}
		return addrSevice.setDefault(request,qto);
	}

	//移除地址
	@NoRepeatSubmit
	@RequestMapping("/removeAddr")
	public HttpResult removeAddr(HttpServletRequest request,@RequestBody ComposeCommitDto qto) {
		if (StringUtils.isEmpty(qto.getReceivingAddrId())){
			return HttpResult.PARAM_ERROR;
		}
		return addrSevice.removeAddr(request,qto);
	}
}
